//
//  ModifyBottomToolbar.m
//  HpnotiqCustomize
//
//  Created by Harmandeep Singh on 09/06/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ModifyBottomToolbar.h"
#import "ToolbarShapeItemView.h"


#define kWidth 768
#define kHeight 200


@implementation ModifyBottomToolbar

@synthesize viewDelegate;

- (id)initWithFrame:(CGRect)frame andShapeFilesNames:(NSArray *)arrayOfShapeFiles
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        self.backgroundColor = [UIColor blackColor];
        
        
        
        
        
        ToolbarShapeItemView *shapeItemView = [[ToolbarShapeItemView alloc] initWithFrame:CGRectMake(0,
                                                                                                     0,
                                                                                                     50,
                                                                                                     50)
                                                                           andSVGFileName:@"star"];
        shapeItemView.mOriginalFrameInToolbar = shapeItemView.frame;
        [self addSubview:shapeItemView];
        [shapeItemView release];
        
        
        
        
        self.frame = CGRectMake(frame.origin.x,
                                frame.origin.y,
                                kWidth,
                                kHeight);
        
        
        
        
        mSizeSliderView = [[UISlider alloc] initWithFrame:CGRectMake(300,
                                                                     50,
                                                                     200,
                                                                     23)];
        mSizeSliderView.minimumValue = 0.5;
        mSizeSliderView.maximumValue = 4.0;
        [mSizeSliderView addTarget:self action:@selector(valueChangedOnSizeSlider:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:mSizeSliderView];
        
        
        
        
        
        mRotationSliderView = [[UISlider alloc] initWithFrame:CGRectMake(300,
                                                                         100,
                                                                         200,
                                                                         23)];
        mRotationSliderView.minimumValue = 0;
        mRotationSliderView.maximumValue = 360;
        [mRotationSliderView addTarget:self action:@selector(valueChangedOnRotationSlider:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:mRotationSliderView];
        
        
        
        [self modifyTheToolbarForSelectionOfModifyItemView:nil];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/


- (void)dealloc {
    
    [mRotationSliderView release];
    [mSizeSliderView release];
}




- (void)valueChangedOnSizeSlider:(id)sender
{
    if([viewDelegate respondsToSelector:@selector(modifyBottomToolbar:userChangedValueOnSizeSliderToValue:)])
    {
        [viewDelegate modifyBottomToolbar:self userChangedValueOnSizeSliderToValue:mSizeSliderView.value];
    }
}


- (void)valueChangedOnRotationSlider:(id)sender
{
    if([viewDelegate respondsToSelector:@selector(modifyBottomToolbar:userChangedValueOnRotationSliderToValue:)])
    {
        [viewDelegate modifyBottomToolbar:self userChangedValueOnRotationSliderToValue:mRotationSliderView.value];
    }
}



- (void)modifyTheToolbarForSelectionOfModifyItemView:(ModifyItemView *)itemView
{
    if(itemView)
    {
        mSizeSliderView.enabled = YES;
        mSizeSliderView.value = itemView.mScaleTransformValue;
        
        mRotationSliderView.enabled = YES;
        mRotationSliderView.value = itemView.mRotationTransformValue;
    }
    else
    {
        mSizeSliderView.value = 0.0;
        mSizeSliderView.enabled = NO;
        
        mRotationSliderView.value = 0.0;
        mRotationSliderView.enabled = NO;
    }
}


@end
